﻿namespace Foggy.Data
{
    using RestSharp;

    /// <summary>
    /// FogBugz authenticator
    /// Adds token parameter to all requests
    /// </summary>
    public class FogBugzAuthenticator : IAuthenticator
    {
        /// <summary>
        /// Token returned by FogBugz logon
        /// </summary>
        private readonly string token;

        /// <summary>
        /// Initializes a new instance of the <see cref="FogBugzAuthenticator"/> class.
        /// </summary>
        /// <param name="token">The token.</param>
        public FogBugzAuthenticator(string token)
        {
            this.token = token;
        }

        /// <summary>
        /// Authenticates the specified client.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="request">The request.</param>
        public void Authenticate(IRestClient client, IRestRequest request)
        {
            request.AddParameter("token", this.token);
        }
    }
}